package com.chb.system.controller.apis;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chb.system.annotation.OperLogAnnotation;
import com.chb.system.service.RoleService;
import com.chb.system.vo.RoleVo;
import com.hos.entity.sys.Role;
import com.hos.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：张家琪
 * @date ：Created in 2023/12/12 20:17
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("system/api/role")
@Api(value = "角色相关接口", tags = "角色相关接口")
public class APIRoleController {
    @Autowired
    private RoleService roleService;

    @DeleteMapping("deleteRoleByRoleIds/{ids}")
    @ApiOperation(value = "根据角色ID永久删除角色")
    @OperLogAnnotation(business_type = "系统业务-删除角色", operator_type = 1)
    public Result<Integer> deleteRoleByRoleIds(@PathVariable List<Long> ids) {
        return new Result<>(200, "删除成功", roleService.deleteRoleByIds(ids));
    }

    @PostMapping("updateRole")
    @ApiOperation(value = "修改角色信息")
    @OperLogAnnotation(business_type = "系统业务-修改角色", operator_type = 1)
    public Result updateRole(@RequestBody Role role) {
        return new Result<>(200, "修改成功", roleService.updateRole(role));
    }

    @PostMapping("/getRoleByRoleId/{roleId}")
    @ApiOperation(value = "根据角色Id查询到一个角色")
    public Result<Role> getRoleByRoleId(@PathVariable Long roleId) {
        return new Result<Role>(200, "查询成功", roleService.getRoleById(roleId));
    }

    @PostMapping("/addRole")
    @OperLogAnnotation(business_type = "系统业务-添加角色", operator_type = 1)
    @ApiOperation(value = "添加角色")
    public Result<Integer> addRole(Role role) {
        return new Result<>(200, "添加成功", roleService.addRole(role));
    }

    @GetMapping("selectAllRole")
    @ApiOperation(value = "获取所有可用的角色信息")
    public Result<List<Role>> selectAllRole() {
        return new Result<>(200, "查询成功", roleService.selectAllRole());
    }

    @PostMapping("findRoleByCond")
    @ApiOperation(value = "条件查询角色信息")
    public Result<Page<Role>> findRoleByCond(@RequestBody RoleVo roleVo) {
        return new Result<>(200, "请求成功", roleService.findRoleByCond(roleVo));
    }

}